package com.liu.netty.server;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by Administrator on 2019/8/29 0029.
 */
public class ClientsMap {

    private static final ConcurrentHashMap<String,ChannelHandlerContext> sessionChannelMap = new ConcurrentHashMap<>();

    private static final ConcurrentHashMap<String ,String> sessionClientMap = new ConcurrentHashMap<>();

    public static  void addClient(String clientId ,String channelId){
        sessionClientMap.put(clientId,channelId);
    }
    public static  void removeClient(String clientId){
        sessionClientMap.remove(clientId);
    }
    public static  String getChannelId(String clientId){
        return sessionClientMap.get(clientId);
    }

    public static Set<String>  getClientKeys(){
        return sessionClientMap.keySet();
    }


    public static void   addChannel(String sessionId ,ChannelHandlerContext channel){
        sessionChannelMap.put(sessionId,channel);

    }

    public static  ChannelHandlerContext getChannel(String sessionId){
         return  sessionChannelMap.get(sessionId);
    }

    public static  void  removeChannel(String sessionId){
        sessionChannelMap.remove(sessionId);
    }

    public static Map<String,String> getAllClients(){
        return sessionClientMap;
    }

}
